﻿using MediatR;
using SuYuanSystem.Applications;
using SuYuanSystem.Domain;
using SuYuanSystem.Repositories;
using SuYuanSystem.WebApi.MedialRs.Commands.Enterprises;

namespace SuYuanSystem.WebApi.MedialRs.CommandHandlers.Enterprises
{
    public class EnterpriseQueryCommandsHandlers : IRequestHandler<EnterpriseQueryCommands, ApiResult<Enterprise>>
    {
        public EnterpriseQueryCommandsHandlers(IRepository<Enterprise> repository)
        {
            Repository = repository;
        }

        public IRepository<Enterprise> Repository { get; }

        public Task<ApiResult<Enterprise>> Handle(EnterpriseQueryCommands request, CancellationToken cancellationToken)
        {
            ApiResult<Enterprise> result = new ApiResult<Enterprise>();
            result.statusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = Repository.GetAll();
            var entity = list.Result.FirstOrDefault();
            result.Data = entity;
            return Task.FromResult(result);
        }
    }
}
